//*************************************************************************************
//* 作    者： z hunter
//* 创建时间： 2021-09-01 10:18:16
//* 描    述： 资源加载

//* ************************************************************************************
using UnityEngine;
using UFrame.Source;

public class SourceAgent : AgentContext<SourceAgent, ISourceController, SourceController>
{
    public static void StartAsResourceLoad()
    {
        AgentSelf.SwitchResourceLoadCtrl<ResourceLoadCtrl>();
    }

    public static void StartAsFileLoad()
    {
        AgentSelf.SwitchFileLoadCtrl<FileLoadCtrl>(Application.persistentDataPath);
    }

    public static void StartAsBundleLoad()
    {
        AgentSelf.SwitchBundleLoadCtrl<AssetBundleLoadCtrl>(AssetBundleAgent.Instance);
    }

    //绑定资源路径
    public static void RegistSourcePath(int id, string path)
    {
        Instance.RegistSourcePath(id, path);
    }

    //得到资源路径
    public static string FindSourcePath(int sourceID)
    {
        return Instance.FindSourcePath(sourceID);
    }

    //同步加载资源
    public static T LoadSource<T>(string sourcePath, SourceLoadOption option = SourceLoadOption.None) where T : Object
    {
        return Instance.LoadSource<T>(sourcePath, option);
    }

    //异步加载资源
    public static ICustomSourceHandle LoadSourceAsync<T>(string sourcePath, LoadSourceCallBack<T> callBack, SourceLoadOption option = SourceLoadOption.None, object context = null) where T : Object
    {
        return Instance.LoadSourceAsync<T>(sourcePath, callBack, option, context);
    }

    /// 回收资源
    public static void RecoverSource<T>(T obj) where T : Object
    {
        Instance.RecoverSource(obj);
    }

    /// 回收资源
    public static void ReleaseUnUsedSources()
    {
        Instance.ReleaseUnUsedSources();
    }

    /// 同步加载GameObject
    public static GameObject LoadGameObjectInstence(string sourcePath)
    {
        return Instance.LoadGameObjectInstence(sourcePath);
    }

    /// 异步加载GameObject
    public static ICustomSourceHandle LoadGameObjectInstenceAsync(string sourcePath, LoadSourceCallBack<GameObject> callBack, object context = null)
    {
        return LoadGameObjectInstenceAsync(sourcePath, callBack, context);
    }
}
